<?php
class view_member
{
	var $ipsclass;
	
	function auto_run()
	{
		if($this->ipsclass->vars['market_show_money'] || $this->ipsclass->vars['market_show_inventory'] || $this->ipsclass->member['mgroup'] == $this->ipsclass->vars['admin_group']);
		else
		{
			$this->ipsclass->market_class->redirect("","",array('instant'=>1));
		}
		
		$this->ipsclass->input['mid'] = intval($this->ipsclass->input['mid']);
		
		if(!($member = $this->ipsclass->DB->build_and_exec_query(array('select'=>'*','from'=>'members','where'=>"id=".$this->ipsclass->input['mid']))))
		{
			$this->ipsclass->market_class->redirect("","",array('instant'=>1));
		}
		
		$this->ipsclass->output = $this->output_member($member);
		$this->ipsclass->market_class->disable_menu = 1;
	}
	
	function output_member($member = array())
	{
		$member['money_format'] = $this->ipsclass->do_number_format($member[$this->ipsclass->vars['market_members_field']]);
		if($this->ipsclass->vars['market_show_money'] || $this->ipsclass->member['mgroup'] == $this->ipsclass->vars['admin_group'])
		{
			$html .= $this->ipsclass->compiled_templates['skin_market']->pp_money_table($member);
		}
		
		if(($this->ipsclass->vars['market_show_money'] && $this->ipsclass->vars['market_show_inventory']) || $this->ipsclass->member['mgroup'] == $this->ipsclass->vars['admin_group'])
		{
			$html .= "<br />";
		}
		
		if($this->ipsclass->vars['market_show_inventory'] || $this->ipsclass->member['mgroup'] == $this->ipsclass->vars['admin_group'])
		{
			$inv = array();
			$delete = array();
			$this->ipsclass->DB->build_query(array('select'=>'*','from'=>'market_inventory','where'=>"member_id=".$member['id']));
			$this->ipsclass->DB->exec_query();
			while($item = $this->ipsclass->DB->fetch_row())
			{
				if(!is_array($this->ipsclass->cache['market_items'][$item['item']]))
				{
					$delete[] = $item['i_id'];
					continue;
				}
				if($item['expired'] && $item['expired'] < time())
				{
					$delete[] = $item['i_id'];
					continue;
				}
				$inv[$item['item']][$item['i_id']] = $item;
			}
			if(count($delete))
			{
				$this->ipsclass->DB->do_delete('market_inventory',"i_id IN (".implode(', ',$delete).")");
			}
			$inventory = array();
			foreach($inv as $item_id => $item_group)
			{
				$description = $this->ipsclass->parser->pre_display_parse($this->ipsclass->parser->pre_db_parse($this->ipsclass->market_class->items_loaded[$item_id]->parse_group_description($item_group)));
				$inventory[$item_id] = array($description,count($item_group));
			}
			
			$html .= $this->ipsclass->compiled_templates['skin_market']->pp_inventory_table($inventory);
		}
		
		return $html;
	}
}
?>